﻿$.widget("socaloud.twitterAudienceWidget", {

    options: {
        template: 'templates/twitter-audience-template.html'
    },

    _create: function () {
        var self = this;

        var content = Extension.getTemplate(self.options.template);
        self.element.append(content);

        self.options.viewModel = {
            popularTweets: ko.observableArray([]),
            popularMedia: ko.observableArray([])
        };

        ko.applyBindings(self.options.viewModel, self.element[0]);

        Repository.Twitter.getPopularTweets(self.options.query, function (data) {
            if (!!data) {
                self.options.viewModel.popularTweets(data.results || []);
            }
        });


    },

    _destroy: function () {
        this.element.html('');
    }
});